﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MercuryFE
{
    public partial class SearchMusic : Form
    {
        private int _menuId;

        public SearchMusic(int menuID)
        {
            InitializeComponent();
            _menuId = menuID;
        }

        private void SearchMusic_Load(object sender, EventArgs e)
        {
            populateControls();
        }

        private void populateControls()
        {
            // we only need to populate genre
            List<string> genres = LauncherLib.getMusicGenreList();

            cbGenre.Items.Clear();
            cbGenre.Items.AddRange(genres.ToArray());

        }

        private void btnSearch_Click(object sender, EventArgs e)
        {
            string title = tbTitle.Text;
            if (title.Trim() == "")
                title = null;

            string artists = tbArtists.Text;
            if (artists.Trim() == "")
                artists = null;

            string genre = (string)cbGenre.SelectedItem;

            DataTable dt = LauncherLib.searchMusic(title, artists, genre);


            dgvCollections.DataSource = dt;
            dgvCollections.Columns["JBCollectionID"].Visible = false;
            //lblSearchGamesResults.Text = "Number of Games returned: " + searchGames.Rows.Count.ToString();
            this.Enabled = true;
        }

        private void btnAddMusic_Click(object sender, EventArgs e)
        {
            DataTable searchMusic = (DataTable)dgvCollections.DataSource;

            string error = "";
            if (!LauncherLib.addMusic(_menuId, searchMusic, ref error))
            {
                MessageBox.Show("Error adding music to menu" + Environment.NewLine + error, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                //return;
            }


            this.Close();
        }
    }
}
